package com.base.model;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class ContextDefinition<T> {
	private String name;
    private int imgId; //btn的图标
	private Class<? extends T> viewClass; //activity or fragment
    private Bundle data;
	
	public ContextDefinition() {
	}
	
	public ContextDefinition(String name, Class<? extends T> viewClass) {
		this.name = name;
		this.viewClass = viewClass;
	}

    public ContextDefinition(String name, int imgId, Class<? extends T> viewClass) {
        this.name = name;
        this.imgId = imgId;
        this.viewClass = viewClass;
    }

    public ContextDefinition(String name, int imgId, Class<? extends T> viewClass, Bundle data) {
        this.name = name;
        this.imgId = imgId;
        this.viewClass = viewClass;
        this.data = data;
    }

    public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Class<? extends T> getViewClass() {
		return viewClass;
	}
	public void setViewClass(Class<? extends T> viewClass) {
		this.viewClass = viewClass;
	}

    public int getImgId() {
        return imgId;
    }

    public void setImgId(int imgId) {
        this.imgId = imgId;
    }

    public Bundle getData() {
        return data;
    }

    public void setData(Bundle data) {
        this.data = data;
    }


    //获取界面名称列表
	public static <T> List<String> getNames(Collection<ContextDefinition<T>> collection) {
		return new ArrayList<String>(Arrays.asList(getNamesArr(collection)));
	}
	
	public static <T> String[] getNamesArr(Collection<ContextDefinition<T>> collection) {
		String[] ret = new String[collection.size()];
		int i = 0;
		for(ContextDefinition<?> v : collection) {
			ret[i++] = v.getName();
		}
		return ret;
	}
	
	//获取界面class对象列表
	public static <T> List<Class<? extends T>> getClazes(Collection<ContextDefinition<T>> collection) {
		List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>();
		for(ContextDefinition<T> v : collection) {
			ret.add(v.getViewClass());
		}
		return ret;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> Class<? extends T>[] getClazesArr(Collection<ContextDefinition<T>> collection) {
		return (Class<? extends T>[])getClazes(collection).toArray();
	}
}
